package net.flyinggroup.lab.init;

import im.aop.loggers.advice.before.LogBefore;
import lombok.extern.java.Log;
import net.flyinggroup.lab.model.Employee;
import net.flyinggroup.lab.repository.EmployeeRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class DataInitializer implements CommandLineRunner {
    private final EmployeeRepository repository;

    public DataInitializer(EmployeeRepository repository) {
        this.repository = repository;
    }

    @Override
    @LogBefore
    public void run(String... args) throws Exception {
        // 初始化用户数据
        Employee walker = new Employee("walker", "zhang", "walker@qq.com");
        Employee david = new Employee("david", "zhang", "david@qq.com");
        repository.save(walker);
        repository.save(david);
    }
}